/**
 * Copyright &copy; 2015-2020 <a href="http://www.easyhis.com/">easyhis</a> All rights reserved.
 */
package com.easy.modules.iim.service.impl;

import com.easy.core.persistence.Page;
import com.easy.core.service.impl.BaseServiceImpl;
import com.easy.modules.iim.entity.MailCompose;
import com.easy.modules.iim.mapper.MailComposeMapper;
import com.easy.modules.iim.service.MailComposeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * 发件箱Service
 * @author easy
 * @version 2015-11-13
 */
@Service
@Transactional(readOnly = true)
public class MailComposeServiceImpl extends BaseServiceImpl implements MailComposeService {
	/**
	 * 持久层对象
	 */
	@Autowired
	private MailComposeMapper mapper;


	public int getCount(MailCompose mailCompose) {
		return mapper.getCount(mailCompose);
	}


	/**
	 * 获取单条数据
	 * @param id
	 * @return
	 */
	public MailCompose get(String id) {
		return mapper.get(id);
	}

	/**
	 * 获取单条数据
	 * @param entity
	 * @return
	 */
	public MailCompose get(MailCompose entity) {
		return mapper.get(entity);
	}

	/**
	 * 查询列表数据
	 * @param entity
	 * @return
	 */
	public List<MailCompose> findList(MailCompose entity) {
		dataRuleFilter(entity);
		return mapper.findList(entity);
	}

	/**
	 * 查询分页数据
	 * @param page 分页对象
	 * @param entity
	 * @return
	 */
	public Page<MailCompose> findPage(Page<MailCompose> page, MailCompose entity) {
		dataRuleFilter(entity);
		entity.setPage(page);
		page.setList(mapper.findList(entity));
		return page;
	}

	/**
	 * 保存数据（插入或更新）
	 * @param entity
	 */
	@Transactional(readOnly = false)
	public void save(MailCompose entity) {
		if (entity.getIsNewRecord()){
			mapper.insert(entity);
		}else{
			mapper.update(entity);
		}
	}

	/**
	 * 删除数据
	 * @param entity
	 */
	@Transactional(readOnly = false)
	public void delete(MailCompose entity) {
		mapper.delete(entity);
	}


	/**
	 * 删除全部数据
	 * @param entitys
	 */
	@Transactional(readOnly = false)
	public void deleteAll(Collection<MailCompose> entitys) {
		for (MailCompose entity : entitys) {
			mapper.delete(entity);
		}
	}

	/**
	 * 删除全部数据
	 * @param entitys
	 */
	@Transactional(readOnly = false)
	public void deleteAllByLogic(Collection<MailCompose> entitys) {
		for (MailCompose entity : entitys) {
			mapper.deleteLogic(entity);
		}
	}


	/**
	 * 获取单条数据
	 * @param propertyName, value
	 * @return
	 */
	public MailCompose findUniqueByProperty(String propertyName, Object value){
		return mapper.findUniqueByProperty(propertyName, value);
	}

	/**
	 * 动态sql
	 * @param sql
	 */

	public List<Object> executeSelectSql(String sql){
		return mapper.execSelectSql(sql);
	}

	@Transactional(readOnly = false)
	public void executeInsertSql(String sql){
		mapper.execInsertSql(sql);
	}

	@Transactional(readOnly = false)
	public void executeUpdateSql(String sql){
		mapper.execUpdateSql(sql);
	}

	@Transactional(readOnly = false)
	public void executeDeleteSql(String sql){
		mapper.execDeleteSql(sql);
	}

}